package com.yehaikeji.workflow.common.intercept;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.yehaikeji.workflow.common.assist.assist;

public class MainInterceptor implements HandlerInterceptor {
	
	  private static final String[] IGNORE_URI = {"/js/", ".js", ".css", ".jpg",
	            ".ttf", ".woff", "woff2", ".txt", ".gif", ".png", "/error", ".PNG",".GIF",".JPG",
	            "/userManager/exit","/userManager/userlogin","/app/", "fileuploads","/swagger","/api-docs","/noteModel/receive"};

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		    String url = request.getRequestURL().toString();
		 	for (String s : IGNORE_URI)
	        {
	            if (url.contains(s))
	            {
	                return true;
	            }
	            
	        }
	        
	        if (null == request.getSession()
	                || null == request.getSession().getAttribute("user"))
	        {
	            response.sendRedirect("/workflow/userManager/exit");
	            return false;
	        }
	        else
	        {
	            return true;
	        }
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {

	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		// TODO Auto-generated method stub
		
	}

}
